package com.water.servlet;

import com.water.Service.Impl.WaterServiceImpl;
import com.water.Service.WaterService;
import com.water.domain.ColumnListBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class AddColumnServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("UTF-8");
            String title = req.getParameter("title");
            ColumnListBean columnListBean = new ColumnListBean(title);
            WaterService service = new WaterServiceImpl();
            service.InsertColumn(columnListBean);

            req.getRequestDispatcher("ColumnServlet?currentPage=1").forward(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
